import type { HistoryItem } from '@/interfaces/medicine'
import type { ProColumns } from '@ant-design/pro-components';
import { Tag } from 'antd'

const getColumns: () => ProColumns<HistoryItem>[] = () => {
    return [
        {
            title: '药品名称',
            dataIndex: 'name',
            hideInSearch: true
        },
        {
            title: '生产厂家',
            dataIndex: 'factory',
        },
        {
            title: '规格',
            dataIndex: 'specs',
            hideInSearch: true
        },
        {
            title: '剂型',
            dataIndex: 'type',
            hideInSearch: true
        },
        {
            title: '包装',
            dataIndex: 'pack',
            hideInSearch: true
        },
        {
            title: '单价',
            dataIndex: 'price',
            hideInSearch: true
        },
        {
            title: '生产批号',
            dataIndex: 'batchnumber',
        },
        {
            title: '生产日期',
            dataIndex: 'productdate',
            valueType: 'date',
            sorter: true,
            hideInSearch: true,
        },
        {
            title: '生产日期',
            dataIndex: 'productdate',
            valueType: 'dateRange',
            hideInTable: true,
            search: {
                transform: (value) => {
                    return {
                        productdate_startTime: value[0],
                        productdate_endTime: value[1],
                    };
                },
            },
        },
        {
            title: '有效截止日期',
            dataIndex: 'deaddate',
            valueType: 'date',
            sorter: true,
            hideInSearch: true,
        },
        {
            title: '有效截止日期',
            dataIndex: 'deaddate',
            valueType: 'dateRange',
            hideInTable: true,
            search: {
                transform: (value) => {
                    return {
                        deaddate_startTime: value[0],
                        deaddate_endTime: value[1],
                    };
                },
            },
        },
        {
            title: '出入库',
            dataIndex: 'operate',
            valueType: 'select',
            valueEnum: {
                in: {
                    text: '入库',
                },
                out: {
                    text: '出库',
                },

            },
            hideInTable: true
        },
        {
            title: '出入库',
            key: 'operate',
            dataIndex: 'operate',
            hideInSearch: true,
            render: (_, record) => {
                const isIn = record.operate === '入库'
                return (<Tag color={isIn ? '#a0d911' : '#fa541c'} >
                    {isIn ? '入库' : '出库'}
                </Tag>)
            },
        },
        {
            title: '出入库数量',
            dataIndex: 'operatecount',
            hideInSearch: true,
        },
        {
            title: '出入库时间',
            dataIndex: 'operateTime',
            valueType: 'date',
            sorter: true,
            hideInSearch: true,
        },
        {
            title: '出入库时间',
            dataIndex: 'operateTime',
            valueType: 'dateRange',
            hideInTable: true,
            search: {
                transform: (value) => {
                    return {
                        operateStartDate: value[0],
                        operateEndDate: value[1],
                    };
                },
            },
        },
        {
            title: '操作员',
            dataIndex: 'userName',
            hideInSearch: true
        },
    ];
}

export default getColumns;